<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Config extends CI_Controller{
    function __construct()
    {
      parent::__construct();

      if( !$this->session->userdata('isLoggedIn') ) {
          redirect('/login/show_login');
      }
    }
    //controller for display mod_name on sidebar
    public function config_check(){
        $this->load->model('config_m');
        
        $isadmin = $this->session->userdata('isadmin');
        $result=$this->config_m->get_config_detail();
        if( $result ){
            $data['sidebar_list'] = $result;
        }
        $data['sidebar_type'] = "config";
        $data['is_admin'] = $isadmin;
        $data['error_info'] = "";
        $this->load->view('config',$data);
    }
    // controller for display config list by mod_id
    public function config_mod($mod_id=1){
        $this->load->model('config_m');
        $resultAll=$this->config_m->get_config_detail();
        if( $resultAll ){
            $data['sidebar_list'] = $resultAll;
        }
        $result=$this->config_m->get_config_file($mod_id);
        if( $result ){
            $configFiles=explode(";",$result['mod_config_files']);
            foreach( $configFiles as $item) {
                $config_list[] = $item;
            }
            $data['config_list'] = $config_list;
            $data['curmod'] = $result['mod_name'];
        }
        $data['sidebar_type'] = "config";
        $data['is_admin'] = $this->session->userdata('isadmin');
        $data['error_info'] = "";
        $this->load->view('config',$data);
    }
    // controller for open config file
    public function config_open(){
        defined('CONFIGPATH') OR exit('config  path not exist');
        $mod_name = $this->input->post('modname');
        $config_name = $this->input->post('configname');
        
        //$config_center_path = "/data/projectdata/config_center/";
        $config_file_path = CONFIGPATH ."config_center/". $mod_name . "/" . $config_name;
        if ( file_exists($config_file_path) ) {
            $configContent = file_get_contents($config_file_path);
        }else{
            $configContent=sprintf("%s not exist",$config_file_path);
        }
        echo $configContent;
    }

}


